package com.useenum;

public enum DemoEnum {
    RED("红色",1),GREEN("绿色",2),BLUE("蓝色",3),YELLOW("黄色",4);
    private String color;
    private Integer num;

    private DemoEnum(String color, Integer num) {
        this.color = color;
        this.num = num;
    }

    public static String getName(Integer num) {
        for (DemoEnum value : DemoEnum.values()) {
            if (value.getNum() == num) {
                return value.color;
            }
        }
        return null;
    }

    public String getEnumName(DemoEnum demoEnum) {
        return demoEnum.name();
    }


    @Override
    public String toString() {
        return "DemoEnum{" +
                "color='" + color + '\'' +
                ", num=" + num +
                '}';
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}
